package com.xb;

import com.xb.Entity.Customers;
import org.junit.Test;

import java.lang.reflect.Type;
import java.sql.Connection;
import java.sql.Date;
import java.util.List;

public class CustomersDaoImpl extends BaseDao<Customers> implements CustomersDao{


    @Override
    public void insert(Connection connection, Customers customers) {
        String sql = "insert into customers(name,email,birth) values(?,?,?)";
        DclSql(connection,sql,customers.getName(),customers.getEmail(),customers.getBirth());

    }

    @Override
    public void deleteById(Connection connection, int id) {
        String sql = "delete from customers where id = ?";
        DclSql(connection,sql,id);
    }

    @Override
    public void updateById(Connection connection, int id, Customers customers) {
        String sql = "update customers set name=?,email=? where id = ?";
        DclSql(connection,sql,customers.getName(),customers.getEmail(),id);
    }

    @Override
    public Customers getCustomersById(Connection connection, int id) {
        String sql = "select name,email,birth from customers where id = ?";
        Customers customers =  selectInfo(connection, sql,id);
        return customers;
    }

    @Override
    public List<Customers> getCustomers(Connection connection) {
        String sql = "select id,name,email,birth from customers";
        List<Customers> customers = selectGetDataBytrasaction(connection, sql, null);
        return customers;
    }

    @Override
    public Date getMaxBirth(Connection connection) {
        String sql = "select Max(birth) from customers";
        return selectByFunction(connection,sql,null);
    }

    @Override
    public Long getCount(Connection connection) {
        String sql = "select count(*) from customers";
        return selectByFunction(connection,sql,null);
    }
}
